/**
 * 获取颜色值
 */
 const color2RGB = (color:string):any[] => {
    if (typeof color !== 'string' || (color.length !== 7 && color.length !== 4)) return [0, 0, 0];
    color = color.substr(1);
    if (color.length === 3) {
      return color.split('').map(str => parseInt(str + str, 16));
    }
  
    let result = [];
    for (let i = 0; i < 6; i += 2) {
      result.push(parseInt(color.substr(i, 2), 16));
    }
  
    return result;
  }
  
export const changeColor = (colorStr:string, correctionFactor:any) => {
    let color = color2RGB(colorStr)
    let red:number = parseFloat(color[0]);
    let green:number = parseFloat(color[1]);
    let blue:number = parseFloat(color[2]);
  
    if (correctionFactor < 0) {
      correctionFactor = 1 + correctionFactor;
      red *= correctionFactor;
      green *= correctionFactor;
      blue *= correctionFactor;
    }
    else {
      red = (255 - red) * correctionFactor + red;
      green = (255 - green) * correctionFactor + green;
      blue = (255 - blue) * correctionFactor + blue;
    }
  
    if (red < 0) red = 0;
  
    if (red > 255) red = 255;
  
    if (green < 0) green = 0;
  
    if (green > 255) green = 255;
  
    if (blue < 0) blue = 0;
  
    if (blue > 255) blue = 255;
  
    red = parseInt(red);
    green = parseInt(green);
    blue = parseInt(blue)
   
  
    return [red, green, blue];
  }
